//
//  IndexListView.swift
//  maozzi-rss
//
//  Created by 帽子 on 2020/5/22.
//  Copyright © 2020 帽子. All rights reserved.
//  首页view

import SwiftUI

struct IndexListView: View {
    @EnvironmentObject var userData: UserData
    @State var isShowing: Bool = false

    var body: some View {
        List {
            NavigationLink(destination: UnreadListView().environmentObject(self.userData)) {
                IndexRowView(indexItem: IndexItem(id: 1, title: "未读消息", category: "index", imageName: "message"), newsCount: self.userData.newsData.count)
            }
            NavigationLink(destination: RecentListView().environmentObject(self.userData)) {
                IndexRowView(indexItem: IndexItem(id: 2, title: "最近阅读", category: "index", imageName: "clock"), newsCount: self.userData.recentData.count)
            }
        }.background(IndexRefeshView(action: {
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                self.isShowing.toggle()
                self.userData.newsData = RSSUtil.get()
            }
        }, isShowing: self.$isShowing))
    }
}

struct IndexListView_Previews: PreviewProvider {
    static var previews: some View {
        IndexListView()
            .environmentObject(UserData())
    }
}
